// TOWN SCRIPT
//    Town 8: Lighthouse - first floor

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 8, 3 = spiritual herb bush
// 8, 5 = town dead...

begintownscript;

variables;

short choice, ii;

body;

beginstate INIT_STATE;
	turn_off_training(1);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	// if town not dead and actually inside lighthouse, create wandering monsters...
	// -- note, town_status(x) call does not work so have to use 'dead' flags
	if ((get_flag(8, 5) == 0) && (get_flag(8, 4) > 0)) {
		// maybe create wandering monsters
		ii = get_ran(1, 1, 100);
		if (ii > 97) {
			message_dialog("Some undead rise up through the floor!", "");
			ii = get_ran(1, 1, 4);
			if (ii == 1) {
				place_monster(21, 21, 138, 0);
				place_monster(20, 22, 232, 0);
				place_monster(22, 22, 232, 0);
			}
			else if (ii == 2) {
				place_monster(21, 21, 139, 0);
				place_monster(20, 22, 121, 0);
				place_monster(22, 22, 121, 0);
			}
			else if (ii == 3) {
				place_monster(21, 21, 138, 0);
				place_monster(20, 22, 136, 0);
				place_monster(22, 22, 136, 0);
			}
			else if (ii == 4) {
				place_monster(21, 21, 139, 0);
				place_monster(20, 22, 128, 0);
				place_monster(22, 22, 128, 0);
			}
		}
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(6, "Good job!");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(7, "Thank you.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(8, "Thanks for clearing the spirits.");
	}
	if (get_ran(1, 0, 100) < 6) {
		text_bubble_on_char(9, "Yah! Undead are gone.");
	}
break;

beginstate 10;
	// stairs up to 2nd level
	move_to_new_town(9, 18, 19);
	block_entry(1);
break;

beginstate 11;
	if (get_flag(8, 1) == 0) {
		set_flag(8, 1, 1);
		message_dialog("You enter the bottom level of the lighthouse.", "A lever along the wall seems to open the gate across from you.");
	}
	set_flag(8, 4, 0); // clear 'in lighthouse' flag
break;

beginstate 12;
	if (get_flag(8, 2) == 0) {
		set_flag(8, 2, 1);
		message_dialog("As you enter the main living area of the lighthouse, you see undead everywhere out of the corner of your eye.", "A shiver runs up your spine.");
	}
	set_flag(8, 4, 1); // set 'in lighthouse' flag
break;
